﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MikroMagazaObject
{
    public partial class frmListe : Form
    {
        Mikro mikro = new Mikro();
        Dictionary<string, string> _values = new Dictionary<string, string>();
        public Dictionary<string, string> Values { get { return _values; } }

        public enum ListeTipleri
        {
            StokKoduAra,
            StokAdiAra,
            Cari,
            IrsaliyeListe,
            DepoSevkListe,
            SiparisListe
        }

        public ListeTipleri ListeTipi { get; set; }
        public string Filtre { get; set; }

        public frmListe()
        {
            InitializeComponent();
        }

        private void frmListe_Load(object sender, EventArgs e)
        {
            switch (ListeTipi)
            {
                case ListeTipleri.StokKoduAra:
                    gridControl1.DataSource = mikro.StokListe(Filtre, true);
                    gridView1.Columns["KdvOrani"].Visible = false;
                    gridView1.Columns["KdvSira"].Visible = false;
                    break;
                case ListeTipleri.StokAdiAra:
                    gridControl1.DataSource = mikro.StokListe(Filtre, false);
                    gridView1.Columns["KdvOrani"].Visible = false;
                    gridView1.Columns["KdvSira"].Visible = false;
                    break;
                case ListeTipleri.Cari:
                    gridControl1.DataSource = mikro.CariListe();
                    gridView1.Columns["Value"].Caption = "Cari Kodu";
                    gridView1.Columns["Text"].Caption = "Cari Ünvanı";
                    break;
                case ListeTipleri.IrsaliyeListe:
                    gridControl1.DataSource = mikro.ListEvrak(EvrakTipleri.AlisIrsaliyesi);
                    break;
                case ListeTipleri.DepoSevkListe:
                    gridControl1.DataSource = mikro.ListEvrak(EvrakTipleri.DepoSevk);
                    break;
                case ListeTipleri.SiparisListe:
                    gridControl1.DataSource = mikro.ListEvrak(EvrakTipleri.VerilenSiparis);
                    break;
            }
            gridView1.BestFitColumns();
        }

        private void gridControl1_DoubleClick(object sender, EventArgs e)
        {
            ValDoldur();
            DialogResult = System.Windows.Forms.DialogResult.OK;
        }

        private void ValDoldur()
        {
            if (gridView1.FocusedRowHandle > -1)
            {
                foreach (DevExpress.XtraGrid.Columns.GridColumn item in gridView1.Columns)
                {
                    _values.Add(item.Name.Replace("col", ""), gridView1.GetFocusedRowCellValue(item).ToString());
                }
            }
        }

        private void gridControl1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                ValDoldur();
                DialogResult = System.Windows.Forms.DialogResult.OK;
            }
        }
    }
}
